/*
	File: data/scripts/item_set-material-diffuse.nut
	Author: GameStart3d.com
*/

/*!
	@short	ItemSetMaterialDiffuse
	@author	GameStart3d.com
*/
class	ItemSetMaterialDiffuse
{
	geo 		=	0
	mat			=	0
	rgb_color	=	0
	lamp		=	0

	/*!
		@short	OnUpdate
		Called during the scene update, each frame.
	*/
	function	OnUpdate(item)
	{
	}

	/*!
		@short	OnSetup
		Called when the item is about to be setup.
	*/
	function	OnSetup(item)
	{
		lamp = ItemCastToLight(ItemGetChild(item, "pointlight"))
		geo = ItemGetGeometry(item)
		mat = GeometryGetMaterialFromIndex(geo, 0)
		local	pos = ItemGetWorldPosition(item)
		pos = pos.Normalize()
		pos = pos + Vector(1.0,1.0,1.0)
		pos = pos.Scale(0.5)
		rgb_color = pos
		print("ItemSetMaterialDiffuse::OnSetup() rgb_color = " + rgb_color.x + "," + rgb_color.y + "," + rgb_color.z)
		MaterialSetDiffuse(mat, rgb_color)
		LightSetDiffuseColor(lamp, rgb_color)
	}
}
